<template>
  <div class="menu">
    <span
      v-for="(item, index) in menuItems"
      :key="index"
      :class="['menu-item', { active: activeIndex === index }]"
      @click="setActive(index)"
    >
      {{ item }}
    </span>
  </div>
</template>

<script setup>
import { ref, defineEmits } from 'vue'

// 定义菜单项
const menuItems = ['足球推荐', '篮球推荐']

// 当前激活的菜单项索引
const activeIndex = ref(0)

// 定义一个 emit 事件
const emit = defineEmits(['updateActiveIndex'])

// 设置当前激活的菜单项
const setActive = (index) => {
  activeIndex.value = index

  // 传给父级组件
  emit('updateActiveIndex', index + 1) // index + 1 to send 1 for soccer and 2 for basketball
}
</script>

<style scoped lang="scss">
.menu {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #e2eeff;
  height: 60px;
  padding: 0px 20px;
  .menu-item {
    margin-right: 40px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    height: 100%;
    display: flex;
    align-items: center;
    border-bottom: 2px solid transparent;

    &.active {
      color: #16b13a;
      border-bottom: 2px solid #16b13a;
    }
  }
}
</style>
